package com.googlecodes.tfhwiz.resourceutil.impl;

import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;

import com.googlecodes.tfhwiz.resourceutil.ResourceLoader;
import com.googlecodes.tfhwiz.resourceutil.ResourceParser;

/**
 *
 *
 */
public class FileResourceLoader<R> implements ResourceLoader<R> {
    private File file;
    private ResourceParser<R> parser;
    public FileResourceLoader(File f, ResourceParser<R> parser) {
        this.file = f;
        this.parser = parser;
    }
    @Override
    public R load() throws IOException {
        InputStream is = null;
        try {
            is = new FileInputStream(file);
            R ret = parser.parse(is);
            return ret;
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }

    @Override
    public long getTimestamp() {
        return file.lastModified();
    }
}

